{% extends "base.html" %}

{% block title %}任务列表{% endblock %}

{% block active7 %}class="active-menu"{% endblock %}

{% block css %}

{% endblock %}

{% block body %}
                    <!-- 表格 -->
                    <div class="panel panel-default">
                        <div class="panel-heading">任务列表
{#                                 <button type="button" class="btn btn-primary" id="addTargetBtn">添加目标</button>#}
                        </div>
                    <!-- 结果 -->
                        <div class="panel-body">
                        <!--检索模块 -->
{#                        <div>#}
{#                        <form method="GET" class="form-inline mb-3" id="select_filter" action="{{ url_for('task.select_port') }}">#}
{#                            <div class="form-group">#}
{#                                <label for="filter">搜索字段：</label>#}
{#                                <select class="form-control" name="filter" id="filter">#}
{#                                    <option value="target_ip" name="target_ip" {% if filter == 'target_ip' %}selected{% endif %}>状态</option>#}
{#                                </select>#}
{#                            </div>#}
{#                            <div class="form-group">#}
{#                                <input type="text" class="form-control" name="q" placeholder="搜索关键字" value="{{ q }}">#}
{#                            </div>#}
{#                                <button type="submit" class="btn btn-primary" id="selectBtn">搜索</button>#}
{#                        </form>#}
{#                        </div>#}



                            <!-- 展示模块 -->
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
                                            <th> # </th>
                                            <th>任务</th>
                                            <th>识别状态</th>
                                            <th>创建时间</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    {% for i in data %}
                                        <tr>
                                            <td>{{ i.id }}</td>
                                            <td>{{ i.taskname }}</td>
                                            <td>
                                                {% if i.status == '已完成' %}
                                                <span class="label label-success">{{i.status}}</span>
                                                {% elif i.status == '失败' %}
                                                    <span class="label label-warning">{{i.status}}</span>
                                                {% elif i.status == '进行中'  %}
                                                <span class="label label-danger">{{i.status}}</span>
                                                {% endif %}
                                            </td>
                                            <td>{{ i.create_time}}</td>
                                            <td><form action="{{ url_for('task.stoptask',id = i.id) }}">
                                                <button class="btn btn-sm btn-danger" data-toggle="modal" id="deletetask"
                                                        data-target="#confirmDeleteModal">删除</button></form>
                                            </td>
                                        </tr>
                                    {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                        <!--  -->
                        <!-- 分页模块 -->
                        <div>
  <nav class="mt-4">
    <ul class="pagination justify-content-center">
      {% if page > 1 %}
        <li class="page-item"><a class="page-link" href="?page={{ page - 1 }}">上一页</a></li>
      {% else %}
        <li class="page-item disabled"><span class="page-link">上一页</span></li>
      {% endif %}

      {% if total_pages <= 7 %}
        {% for p in range(1, total_pages + 1) %}
          {% if p == page %}
            <li class="page-item active"><a class="page-link" href="#">{{ p }}</a></li>
          {% else %}
            <li class="page-item"><a class="page-link" href="?page={{ p }}">{{ p }}</a></li>
          {% endif %}
        {% endfor %}
      {% else %}
        {% if page <= 4 %}
          {% for p in range(1, 6) %}
            {% if p == page %}
              <li class="page-item active"><a class="page-link" href="#">{{ p }}</a></li>
            {% else %}
              <li class="page-item"><a class="page-link" href="?page={{ p }}">{{ p }}</a></li>
            {% endif %}
          {% endfor %}
          <li class="page-item disabled"><span class="page-link">...</span></li>
          <li class="page-item"><a class="page-link" href="?page={{ total_pages }}">{{ total_pages }}</a></li>
        {% elif page >= total_pages - 3 %}
          <li class="page-item"><a class="page-link" href="?page=1">1</a></li>
          <li class="page-item disabled"><span class="page-link">...</span></li>
          {% for p in range(total_pages - 4, total_pages + 1) %}
            {% if p == page %}
              <li class="page-item active"><a class="page-link" href="#">{{ p }}</a></li>
            {% else %}
              <li class="page-item"><a class="page-link" href="?page={{ p }}">{{ p }}</a></li>
            {% endif %}
          {% endfor %}
        {% else %}
          <li class="page-item"><a class="page-link" href="?page=1">1</a></li>
          <li class="page-item disabled"><span class="page-link">...</span></li>
          {% for p in range(page - 2, page + 3) %}
            {% if p == page %}
              <li class="page-item active"><a class="page-link" href="#">{{ p }}</a></li>
            {% else %}
              <li class="page-item"><a class="page-link" href="?page={{ p }}">{{ p }}</a></li>
            {% endif %}
          {% endfor %}
          <li class="page-item disabled"><span class="page-link">...</span></li>
          <li class="page-item"><a class="page-link" href="?page={{ total_pages }}">{{ total_pages }}</a></li>
        {% endif %}
      {% endif %}

      {% if page < total_pages %}
        <li class="page-item"><a class="page-link" href="?page={{ page + 1 }}">下一页</a></li>
      {% else %}
        <li class="page-item disabled"><span class="page-link">下一页</span></li>
      {% endif %}
    </ul>
  </nav>
</div>

                                                {% for msg in get_flashed_messages() %}
                                                           <div> {{ msg }}</div>
                                                                    {% endfor %}
                        </div>
                    </div>
    <!--End Advanced Tables -->
{% endblock %}

{% block js %}

{% endblock %}